﻿using System;
using System.Collections.Generic;
using NUnit.Framework;
using Xenta.Enums;
using Xenta.Operations;

namespace Xenta.Tests.Operations
{
    [TestFixture]
    public class LookupAttributeTests : OperationTest
    {
        protected override IEnumerable<Type> ModelMappings
        {
            get
            {
                return NHMappings.ALL;
            }
        }

        [TestCase(100)]
        public void Can_CRUD(int displayOrder)
        {
            var attribute = Processor.Execute(new CreateLookupAttribute
            {
                DisplayOrder = displayOrder,
                Flags = LookupAttributeFlags.CatalogSupplier
            }).Result;

            Assert.NotNull(attribute);
            attribute.DisplayOrder.AreEqual(displayOrder);
            attribute.AreEqual(Processor.Execute(new GetLookupAttribute
            {
                EntityID = attribute.EntityID
            }).Result);

            displayOrder = displayOrder * 2;
            var upd_attribute = Processor.Execute(new UpdateLookupAttribute
            {
                EntityID = attribute.EntityID,
                DisplayOrder = displayOrder,
                Flags = LookupAttributeFlags.CatalogItem
            }).Result;

            Assert.NotNull(upd_attribute);
            upd_attribute.AreEqual(attribute);
            upd_attribute.DisplayOrder.AreEqual(displayOrder);
            upd_attribute.Flags.AreEqual(LookupAttributeFlags.CatalogItem);

            Processor.Execute(new DeleteLookupAttribute
            {
                EntityID = attribute.EntityID
            });
        }
    }
}
